Write-Host "=== 构建 go-agent.exe ===" -ForegroundColor Green
Write-Host ""

Write-Host "设置Go环境变量..." -ForegroundColor Yellow
$env:GOCACHE = "$PWD\.gocache"  
$env:GOMODCACHE = "$PWD\.gomodcache"
$env:GO111MODULE = "on"

Write-Host "GOCACHE: $env:GOCACHE"
Write-Host "GOMODCACHE: $env:GOMODCACHE"
Write-Host ""

Write-Host "创建缓存目录..." -ForegroundColor Yellow
if (!(Test-Path ".gocache")) { New-Item -ItemType Directory -Path ".gocache" }
if (!(Test-Path ".gomodcache")) { New-Item -ItemType Directory -Path ".gomodcache" }

Write-Host "开始构建..." -ForegroundColor Yellow
$buildResult = go build -o go-agent.exe cmd/agent/main.go
$exitCode = $LASTEXITCODE

if ($exitCode -eq 0) {
    Write-Host "✅ 构建成功！生成文件: go-agent.exe" -ForegroundColor Green
    Write-Host ""
    Write-Host "文件信息:" -ForegroundColor Yellow
    Get-ChildItem go-agent.exe | Format-Table Name, Length, LastWriteTime
    Write-Host "构建完成！可以运行 go-agent.exe 来测试" -ForegroundColor Green
} else {
    Write-Host "❌ 构建失败！错误代码: $exitCode" -ForegroundColor Red
    Write-Host "构建输出: $buildResult" -ForegroundColor Red
}

Write-Host ""
Read-Host "按回车键退出"